package com.woniuxy.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 曾令忠
 * @Description:
 * @Date: 2020/7/12 0012-下午 4:29
 */
@Component
public class MyZuulFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }

    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter() {
        RequestContext requestContext = RequestContext.getCurrentContext();
        HttpServletRequest servlet =  requestContext.getRequest();
        String uri = servlet.getRequestURI();
        System.out.println(uri);
        if(uri.startsWith("/user")){
            return false;
        }
        return true;
    }

    @Override
    public Object run() throws ZuulException {
        System.out.println("拦截器拦截到请求");
        return null;
    }
}
